package kokonut.blog;

import com.google.gdata.client.GoogleService;
import com.google.gdata.client.Query;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.URL;
import java.util.List;

public class BlogManager{

    /**
     * Identificador del blog kokonutcompany.blogspot.com
     */
    private final static String BLOG_ID = "2304485624352180178";
    /**
     * Numero maximo de posts que se piden al blog
     */
    private final static int MAX_RESULTS = 7;

    /**
     * Pide al servicio Google Blogger los ultimos posts escritos en el blog
     * @return Lista de objetos Entry con las entradas recibidas
     * @throws ServiceException
     * @throws IOException
     */
    public static List<Entry> getAllPosts() throws ServiceException, IOException {

        GoogleService myService = new GoogleService("blogger", "Kokonut-WebAppKokonut-1");
        // Request the feed
        URL feedUrl = new URL("http://www.blogger.com/feeds/" + BLOG_ID + "/posts/default");
        Query query = new Query(feedUrl);
        query.setMaxResults(MAX_RESULTS);

        Feed resultFeed = myService.query(query, Feed.class);

        return resultFeed.getEntries();
    }
}